package server.session.handler;

import unit.request.*;

import java.util.HashMap;

/**
 * @author Yuri Denison
 * @since 07.08.11
 */
public class RequestHandlerFactory {
    private static volatile RequestHandlerFactory instance = new RequestHandlerFactory();
    private HashMap<Class, RequestHandler> requests;

    private RequestHandlerFactory() {
        requests = new HashMap<Class, RequestHandler>();

        requests.put(AddContactRequest.class, new AddContactRequestHandler());
        requests.put(CreateNewUserRequest.class, new CreateNewUserRequestHandler());
        requests.put(LoginRequest.class, new LoginRequestHandler());
        requests.put(GetContactListRequest.class, new GetContactListRequestHandler());
        requests.put(SendMessageRequest.class, new SendMessageRequestHandler());
        requests.put(ChangeInfoRequest.class, new ChangeInfoRequestHandler());
        requests.put(SearchUserRequest.class, new SearchUserRequestHandler());
    }

    public RequestHandler getHandler(Class requestClass) {
        return requests.get(requestClass);
    }

    public static synchronized RequestHandlerFactory getInstance() {
        return instance;
    }
}